import { getAreaObj, regularRule, uploadType } from '@/utils/util'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/comprehensiveQueries/components/NewKeywords/components/utils/index'

export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{ label: '户籍地区', prop: 'cr_areas', span: 8 },
		{ label: '户籍地址', prop: 'crAddress', span: 8 },
		{
			label: '证件类型',
			prop: 'identifyType',
			propName: 'identifyTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{ label: '证件号码', prop: 'idCard', span: 8 },
		{ label: '联系方式', prop: 'volunteerPhone', span: 8 },
		{ label: '现居地区', prop: 'areas_name', span: 8 },
		{ label: '现居地址', prop: 'nowAddress', span: 8 },
		{ label: '注册服务点所属区域', prop: 'registerAreaNames', span: 8 },
		{
			label: '志愿者类型',
			prop: 'volunteerType',
			propName: 'volunteerTypeLabel',
			type: 'remoteSelect',
			code: 'VOLUNTEER_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '民族',
			prop: 'nationLabel',
			span: 8,
		},
		{
			label: '政治面貌',
			prop: 'politicalStatusLabel',
			span: 8,
		},
		{
			label: '特长',
			prop: 'specialInterestLabels',
			span: 8,
		},
		{
			label: '学历',
			prop: 'educationLabel',
			span: 8,
		},
		{
			label: '宗教信仰',
			prop: 'religiousBeliefLabel',
			span: 8,
		},

		{
			label: '职业',
			prop: 'volunteerJobLabel',
			span: 8,
		},
		{
			label: '可提供服务内容',
			prop: 'serviceContentLabels',
			span: 8,
		},
		{
			label: '服务内容-其他',
			prop: 'serviceContentOther',
			span: 8,
		},
		{
			label: '承诺书',
			prop: 'promiseImgs',
			custome: 'file',
			labelPosition: 'top',
			span: 8,
		},
		{
			label: '专业服务资质证书',
			prop: 'permitImgs',
			custome: 'file',
			labelPosition: 'top',
			span: 8,
		},
		{
			label: '专业服务资质证书到期时间',
			prop: 'permitTermDate',
			span: 8,
		},
		{
			label: '简介',
			prop: 'volunteerIntroduce',
			span: 24,
		},
		{
			label: '备注',
			prop: 'volunteerNote',
			span: 24,
		},
	],
	customeHeader: {
		type: 'CardTwo',
		title: 'volunteerName',
		avatar: 'volunteerPhoto',
		tipList: [{ prop: 'stateLabel', type: 'tip-success', label: '运营状态' }],
		tagList: [{ prop: 'registerOrganization', type: 'success' }],
		menuBtn: [
			// {
			// 	icon: 'delete',
			// 	label: '删除志愿者',
			// 	type: 'danger',
			// 	operate: 'delete',
			// 	auth: 'view_dpVolunteer_del',
			// 	text: false,
			// 	show: true,
			// 	plain: true,
			// },
		],
	},
}

// 基础
export const BaseFormConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'top',
	column: [
		{
			uploadTip: '照片',
			prop: 'volunteerPhoto',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
		{
			label: '姓名',
			prop: 'volunteerName',
			maxlength: '20',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入志愿者姓名' }],
			span: 8,
		},
		{
			label: '证件类型',
			prop: 'identifyType',
			propName: 'identifyTypeLabel',
			type: 'remoteSelect',
			code: 'ID_CARD_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			changeField: true,
			rules: [{ required: true, message: '请选择证件类型' }],
		},
		{
			label: '身份证号码',
			prop: 'idCard',
			type: 'text',
			rules: [
				{ pattern: regularRule.idCard, message: '请输入正确的身份证号码' },
				{ required: true, message: '请输入身份证号码' },
			],
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'volunteerPhone',
			type: 'input',
			span: 8,
			rules: [
				{ pattern: regularRule.phone, message: '请输入正确的联系方式' },
				{
					required: true,
					message: '请输入联系方式',
				},
			],
		},
		{
			label: '志愿者现居地区',
			prop: 'areas',
			propName: 'areas_name',
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择现居地区' }],
			span: 8,
		},
		{
			label: '现居地址',
			prop: 'nowAddress',
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入现居地址' }],
			span: 8,
		},
		{
			label: '志愿者户籍所属区域',
			prop: 'crAreas',
			propName: 'cr_areas',
			type: 'AplidAreaSelect',
			// rules: [{ required: true, message: '请选择户籍所属区域' }],
			span: 8,
		},
		{
			label: '户籍详细地址',
			prop: 'crAddress',
			maxlength: '140',
			showWordLimit: true,
			type: 'text',
			// rules: [{ required: true, message: '请输入户籍详细地址' }],
			span: 8,
		},
		{
			label: '注册服务点名称',
			prop: 'registerOrganization',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			rules: [{ required: true, message: '请输入注册服务点名称' }],
			span: 8,
		},
		{
			label: '注册服务点所属区域',
			prop: 'registerOrgArea',
			propName: 'registerOrgAreaNames',
			type: 'AplidAreaSelect',
			rules: [{ required: true, message: '请选择注册服务点所属区域' }],
			span: 8,
		},
		{
			label: '民族',
			prop: 'nation',
			propName: 'nationLabel',
			type: 'remoteSelect',
			code: 'NATIONALITY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			// rules: [{ required: true, message: '请选择所在民族' }],
			span: 8,
		},
		{
			label: '政治面貌',
			prop: 'politicalStatus',
			propName: 'politicalStatusLabel',
			type: 'remoteSelect',
			code: 'POLITICAL_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '宗教信仰',
			prop: 'religiousBelief',
			propName: 'religiousBeliefLabel',
			type: 'remoteSelect',
			code: 'RELIGIOUS_BELIEF',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '学历',
			prop: 'education',
			propName: 'educationLabel',
			type: 'remoteSelect',
			code: 'EDUCATION_DEGREE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '特长',
			prop: 'specialInterest',
			propName: 'specialInterestLabels',
			type: 'remoteSelect',
			code: 'SPECIALTY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 8,
		},

		{
			label: '职业',
			prop: 'volunteerJob',
			propName: 'volunteerJobLabel',
			type: 'remoteSelect',
			code: 'OCCUPATION_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '志愿者类型',
			prop: 'volunteerType',
			propName: 'volunteerTypeLabel',
			type: 'remoteSelect',
			code: 'VOLUNTEER_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '可提供服务内容',
			prop: 'serviceContents',
			propName: 'serviceContentLabels',
			type: 'remoteSelect',
			code: 'SERVICE_CONTENTS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 24,
		},
		{
			label: '简介介绍',
			prop: 'volunteerIntroduce',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			span: 12,
		},
		{
			label: '备注',
			prop: 'volunteerNote',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			span: 12,
		},
		{
			label: '服务内容-其他',
			prop: 'serviceContentOther',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			span: 24,
		},
		{
			label: '承诺书',
			prop: 'promiseImgs',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
		{
			label: '专业服务资质证书',
			prop: 'permitImgs',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
		{
			label: '证书到期时间',
			prop: 'permitTermDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
		},
	],
}



const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '注册地区', prop: 'tableAreaName', width: 200 },
		{ label: '注册服务点', prop: 'registerOrganization' },
		{ label: '身份证号', prop: 'idCard', plusXing: '2,2' },
		{ label: '姓名', prop: 'volunteerName' },
		{ label: '联系方式', prop: 'volunteerPhone', plusXing: '5,2' },
		{
			label: '类型',
			prop: 'volunteerTypeLabel',
		},
		{
			label: '学历',
			prop: 'educationLabel',
		},
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}
export const api = {
	moreSearch: 'view_dpVolunteer_search',
	reserveSearch: 'view_dpVolunteer_search',
	index: 'view_dpVolunteer_page',
	add: 'view_dpVolunteer_gather',
	edit: 'view_dpVolunteer_edit',
	detail: 'view_dpVolunteer_view',
	delete: 'view_dpVolunteer_del',
	import: 'view_dpVolunteer_import',
	export: 'view_dpVolunteer_export',
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToReserveSearch(BaseFormConfig.column)],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(BaseFormConfig.column)],
}
export const baseConfig = {
	pageName: '志愿者',
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'volunteerName',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	dictcodes: [
		'ID_CARD_TYPE',
		'NATIONALITY',
		'POLITICAL_STATUS',
		'RELIGIOUS_BELIEF',
		'EDUCATION_DEGREE',
		'SPECIALTY',
		'OCCUPATION_TYPE',
		'VOLUNTEER_TYPE',
		'SERVICE_CONTENTS',
		'GENDER',
	],
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		index: 'view_dpVolunteer_page',
		add: 'view_dpVolunteer_gather',
		edit: 'view_dpVolunteer_edit',
		delete: 'view_dpVolunteer_del',
		import: 'view_dpVolunteer_import',
		export: 'view_dpVolunteer_export',
		detail: 'view_dpVolunteer_view',
		mulitSet: 'mulitSet',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpVolunteer_view',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
		// fullscreen: true
	},
	paramsObj: {
		code: 3021,
	},
	detailConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '证件号码',
				prop: 'idCard',
				type: 'input',
				span: 6,
			},
			{
				label: '注册地区',
				prop: 'registerOrgArea',
				type: 'AplidAreaSelect',
				span: 12,
			},
			{
				label: '姓名',
				prop: 'volunteerName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'volunteerPhone',
				type: 'input',
				span: 6,
			},
			{
				label: '注册服务点',
				prop: 'registerOrganization',
				type: 'input',
				span: 6,
			},
			{
				label: '类型',
				prop: 'volunteerType',
				type: 'remoteSelect',
				code: 'VOLUNTEER_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label: '学历',
				prop: 'education',
				type: 'remoteSelect',
				code: 'EDUCATION_DEGREE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},
	moreSearchConfig,
	reserveSearchConfig,
	beforeOnLoadFormate: (params) => {
		return new Promise((resolve, reject) => {
			const registerArea: any = getAreaObj(params.registerOrgArea, 'register_org')
			console.log('这个地区', params)
			params = toSearchHandle(moreSearchConfig, reserveSearchConfig, params)
			resolve({
				...params,
				...registerArea,
				registerOrgArea: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const registerOrgArea: any = getAreaObj(item, 'register_org', 'set')
			return {
				...item,
				registerAreaNames: registerOrgArea.names,
				tableAreaName: [item.registerOrgAreaName, item.registerOrgStreetName, item.registerOrgCommunityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}
